package com.dubito.concurrency.example.singleton;

import com.dubito.concurrency.annotation.NoRecommend;
import com.dubito.concurrency.annotation.NoThreadSafe;
import com.dubito.concurrency.annotation.ThreadSafe;

/**
 * @author liliang
 * @description: 懒汉模式  双重同步锁
 * @date 2018/6/24.
 */
@NoThreadSafe
public class SingletonExample4 {

    /**
     *  私有构造
     */
    private SingletonExample4(){}

    /**
     * 单例对象
     */
    private static SingletonExample4 instance = null;

    /**
     * 静态的工厂方法
     * @return
     */
    public static SingletonExample4 getInstance () {
        if (instance == null) {
            synchronized (SingletonExample4.class) {
                if (instance == null) {
                    instance = new SingletonExample4();
                }
            }
        }
        return instance;
    }
}
